package com.pmdb.core;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.VerticalSplitPanel;


public class Movie {

   private VerticalSplitPanel vSplit = new VerticalSplitPanel();
   private HorizontalSplitPanel hSplit = new HorizontalSplitPanel();

   /**
    * This is the entry point method.
    */
   public void onModuleLoad() {
      vSplit.setSize("500px", "350px");
      vSplit.setSplitPosition("30%");

      //hSplit.setSize("500px", "350px");
      hSplit.setSplitPosition("30%");

      String randomText = "This is some text to show how the contents on either "
         + "side of the splitter flow.   "
         + "This is some text to show how the contents on either "
         + "side of the splitter flow.   "
         + "This is some text to show how the contents on either "
         + "side of the splitter flow.   ";
      vSplit.setTopWidget(buildList());
      vSplit.setBottomWidget(new HTML(randomText));

      hSplit.setLeftWidget(vSplit);
      hSplit.setRightWidget(buildForm());

      RootPanel.get().add(hSplit);
      buildForm();
   }

   private FlexTable buildList() {
      final FlexTable flexTable = new FlexTable();
      /*flexTable.setWidth("32em");
      flexTable.setCellSpacing(1);
      flexTable.setCellPadding(3);*/
      flexTable.setCellSpacing(0);
      flexTable.setCellPadding(0);
      flexTable.setWidth("100%");
      
      //flexTable.addTableListener(this);
      
      //Header
      flexTable.setHTML(0, 0, "ID");
      flexTable.setHTML(0, 2, "Title");
      flexTable.getRowFormatter().setStyleName(0, "movie-ListHeader");
      
      //Body
      /*List<Movie> lst = Movie.initList();
      int i = 1;
      for (Movie movie : lst) {
         flexTable.setHTML(i, 0, movie.getId());
         flexTable.setHTML(i, 1, movie.getOriginalTitle());
         i++;
      }*/

      return flexTable;
   }

   private FlexTable buildForm() {
      final FlexTable flexTable = new FlexTable();
      flexTable.setWidth("32em");
      flexTable.setCellSpacing(5);
      flexTable.setCellPadding(3);

      VerticalPanel titlePanel = new VerticalPanel();
      titlePanel.add(new HTML("Original title :"));
      titlePanel.add(new TextBox());
      flexTable.setWidget(0, 0, titlePanel);

      VerticalPanel yearPanel = new VerticalPanel();
      yearPanel.add(new HTML("Year :"));
      yearPanel.add(new TextBox());
      flexTable.setWidget(1, 0, yearPanel);

      return flexTable;
   }
}
